#include <math.h>
struct ListNode
{
    int val;
    ListNode *next;
};

class Solution
{
public:
    int getNum(ListNode* head, int& len)
    {
        if (head == nullptr)
        {
            return 0;
        }

        int sum = getNum(head->next, len);
        ++len;
        sum += head->val * (int)pow(2, len - 1);
        return sum;
    }
    int getDecimalValue(ListNode *head)
    {
        int len = 0;
        return getNum(head, len);
    }
};